<?php
/*
 *      config.class.php
 *
 *      Copyright 2010 Patrice Ferlet <metal3d@gmail.com>
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

// $Id: config.class.php 28 2010-12-17 13:28:24Z Metal3d $
// $HeadURL: http://valaya.googlecode.com/svn/trunk/utils/config.class.php $

/**
 *  Config class is used to get/set vars from diffrents namespaces.
 * */
class Config {

	static $instance = null;
	private $values = array();

	/**
	 * Return current instance (singleton) You should use _config() alias
	 *
	 * @return Config $config_instance
	 * */
	public function getInstance() {
		if(is_null(self::$instance)) {
			self::$instance = new self();
		}
		return self::$instance;
	}

	/**
	 * Set config value
	 *
	 * @param string $name
	 * @param mixed $value
	 * @param string $namespace
	 * */
	public function set($name,$value,$namespace='project') {
		if (!isset($this->values[$namespace])) $this->values[$namespace] = array();
		$this->values[$namespace][$name] = $value;
	}

	/**
	 * Get config value
	 *
	 * @param string $name
	 * @param string $namespace
	 * @return mixed $value
	 * */
	public function get($key,$namespace='project') {
		return isset($this->values[$namespace][$key]) ? $this->values[$namespace][$key] : null;
	}
}

